package com.pay.game.central.web.mapper;

import com.github.pagehelper.Page;
import com.pay.game.central.web.bean.PtScore;
import com.pay.game.central.web.bean.Settlement;
import com.pay.game.central.web.bean.Store;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface PtScoreMapper {

    @Insert("insert into pt_score(id,user_id,store_id,value,opt_time)" +
            "values (#{id},#{user_id},#{store_id},#{value,jdbcType=INTEGER},#{opt_time,jdbcType=INTEGER})")
    void insertItem(PtScore ptScore);

    @Select("<script>" +
            "   select score.id,score.store_id,score.value,score.opt_time,u1.name opt_user_name,user.name user_name,store.name store_name from pt_score score " +
            "   join pdd_store store on score.store_id=store.id " +
            "   left  join sys_user user on store.user_id=user.id" +
            "   join sys_user u1 on score.user_id=u1.id" +
            "   where 1=1 " +
            "   <if test=\"username!='' and username!=null\">" +
            "       and user.name like concat(#{username},'%')" +
            "   </if>" +
            "   <if test=\"storeName!='' and storeName!=null\">" +
            "       and store.name like concat(#{storeName},'%')" +
            "   </if>" +
            "   <if test=\"storeId!='' and storeId!=null\">" +
            "       and store.id like concat(#{storeId},'%')" +
            "   </if>" +
            "   order by score.opt_time desc" +
            "</script>")
    Page<Map<String,Object>> list(@Param("storeId") String storeId,@Param("storeName")String storeName,@Param("username")String username);

    @Select("select run_score,score,store_id from settlement where stop_date=#{date} and user_id=#{userId}")
    List<Settlement> getSettlementScore(@Param("userId") String userId, @Param("date") String date);

    @Select("select used_score,score,`loop` from pdd_store where user_id=#{userId}")
    List<Store> getStoreScore(@Param("userId") String userId);

}
